<template>
  <div>
      <h1>购物车</h1>
    <ul>
        <li v-for="(item,i) in goodslist" :key="i">{{item.name}}--{{item.money}}---{{item.count}}---{{item.user}}</li>
    </ul>
    <mt-button @click="clear">清空购物车</mt-button>
  </div>
</template>

<script>
    export default {
        data(){
            return {
                goodslist: []//购物车商品列表
            }
        },
        created(){
            this.getlist()
        },
        methods: {
            clear(){
                //清空购物车数据
                this.$store.commit('clearCar')
                this.goodslist = ''
            },
            getlist(){
                //获取当前用户地购物车数据
                this.$store.state.car.forEach(item=>{
                    if(item.user == this.$store.state.user[0].uname){
                        this.goodslist.push(item)
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>

